<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of manage_users_model
 *
 * @author chandu
 */
class manage_users_model extends model {

    private $data;
    private $data2;
    private $chk;

    // private $userid;



    public function users_display($table) {
        // $this->db = new dbconfig();

        $this->query = "SELECT * FROM $table";

        $this->result2 = $this->execute($this->query) or die(mysql_error());
        while ($this->result_data = $this->fetch_array($this->result2)) {
            $this->data2[] = $this->result_data;
        }
        return $this->data2;
    }

    public function details($table, $id, $col) {
        // $this->db = new dbconfig();

        $this->query = "SELECT * FROM $table where $col = '$id'";

        $this->result2 = $this->execute($this->query);

        while ($this->result_data = mysql_fetch_array($this->result2)) {

            $this->data2[] = $this->result_data;
        }
        return $this->data2;
    }

    public function add_module($table, $suserid) {
        if (isset($_POST['module']) && isset($_POST['Addd']) && isset($_POST['Del']) && isset($_POST['Edit'])) {

            $module = $_POST['module'];
            $addd = $_POST['Addd'];
            $delete = $_POST['Del'];
            $edit = $_POST['Edit'];
            $this->query = "SELECT module, userid FROM $table WHERE module = '$module' and userid = '$suserid'";
            $check = $this->execute($this->query) or die("There is some problem at checking the module and permission is already available or not");
            $check_data = $this->num_rows($check);

            if ($check_data == 0) {

                $this->query = "INSERT INTO $table(module, userid, Addd, Del, Edit)  VALUES ('$module', $suserid, '$addd', '$delete', '$edit')";
                $insert = $this->execute($this->query) or die("There is an error in inserting the module and permissions data in to the db table");
                if ($insert) {
                    return "Success";
                } else {
                    return "Failed";
                }
            } else {

                return "Areadyexist";
            }
        }
    }

    public function get_modules($table) {


        $this->query = "SELECT * FROM $table";

        $this->result2 = $this->execute($this->query);
        while ($this->result_data = mysql_fetch_array($this->result2)) {
            $this->data[] = $this->result_data;
        }
        return $this->data;
    }

}

?>
